package com.bawei.monthdemo2207a.month01.soft

import android.content.Context
import android.text.Editable
import android.text.TextWatcher
import android.util.Log
import android.widget.EditText
import android.widget.LinearLayout
import com.bawei.monthdemo2207a.R

/**
 * 作者：赵亮
 * 时间：2024/12/27 10:55
 * 功能：
 */
class MySearch : LinearLayout {

    constructor(context: Context?) : super(context) {
        // 加载布局
        inflate(context, R.layout.my_search, this)

        findViewById<EditText>(R.id.et_text).addTextChangedListener(object : TextWatcher {
            override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {

            }

            override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
                // Log.i("TAG", "onTextChanged: $p0")
                mListener(p0.toString())
            }

            override fun afterTextChanged(p0: Editable?) {
            }

        })
    }

    lateinit var mListener: (a: String) -> Unit
}